<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * Copyright (c) 2009, Microsoft
<span class='line'>  3</span>  * All rights reserved.
<span class='line'>  4</span>  *
<span class='line'>  5</span>  * Redistribution and use in source and binary forms, with or without
<span class='line'>  6</span>  * modification, are permitted provided that the following conditions are met:
<span class='line'>  7</span>  *     * Redistributions of source code must retain the above copyright
<span class='line'>  8</span>  *       notice, this list of conditions and the following disclaimer.
<span class='line'>  9</span>  *     * Redistributions in binary form must reproduce the above copyright
<span class='line'> 10</span>  *       notice, this list of conditions and the following disclaimer in the
<span class='line'> 11</span>  *       documentation and/or other materials provided with the distribution.
<span class='line'> 12</span>  *     * Neither the name of Microsoft nor the
<span class='line'> 13</span>  *       names of its contributors may be used to endorse or promote products
<span class='line'> 14</span>  *       derived from this software without specific prior written permission.
<span class='line'> 15</span>  *
<span class='line'> 16</span>  * THIS SOFTWARE IS PROVIDED BY Microsoft ''AS IS'' AND ANY
<span class='line'> 17</span>  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
<span class='line'> 18</span>  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<span class='line'> 19</span>  * DISCLAIMED. IN NO EVENT SHALL Microsoft BE LIABLE FOR ANY
<span class='line'> 20</span>  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
<span class='line'> 21</span>  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
<span class='line'> 22</span>  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
<span class='line'> 23</span>  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<span class='line'> 24</span>  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
<span class='line'> 25</span>  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<span class='line'> 26</span>  *
<span class='line'> 27</span>  * @category   Microsoft
<span class='line'> 28</span>  * @package    WebErrorPHPToolkit
<span class='line'> 29</span>  * @subpackage Error
<span class='line'> 30</span>  * @version    $Id: document_helper.js, v 1.0 2009-10-09 08:00:00Z unknown $
<span class='line'> 31</span>  * @copyright  Copyright (c) 2009, Microsoft (http://www.microsoft.com)
<span class='line'> 32</span>  * @author     a-jetann
<span class='line'> 33</span>  *
<span class='line'> 34</span>  * Support functions for DOM.document.
<span class='line'> 35</span>  */</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 37</span> 
<span class='line'> 38</span> </span><span class="COMM">/**
<span class='line'> 39</span>  * Get valid document element, and if not valid throw exception.
<span class='line'> 40</span>  *
<span class='line'> 41</span>  * @param id string Element ID
<span class='line'> 42</span>  * @param fail_throw boolean Throw exception if element is undefined.
<span class='line'> 43</span>  * @return document element.
<span class='line'> 44</span>  * @throw Exception if element is undefined.
<span class='line'> 45</span>  */</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getValidElementById</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">  </span><span class="NAME">fail_throw</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="STRN">'undefined'</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> 
<span class='line'> 50</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">element</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">document.getElementById</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">isNull</span><span class="PUNC">(</span><span class="NAME">element</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">      </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Error</span><span class="PUNC">(</span><span class="STRN">"Element '"</span><span class="PUNC">+</span><span class="NAME">id</span><span class="PUNC">+</span><span class="STRN">"' is not defined."</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">  </span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">element</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> 
<span class='line'> 64</span> </span><span class="COMM">/**
<span class='line'> 65</span>  * Get value of valid document element.
<span class='line'> 66</span>  *
<span class='line'> 67</span>  * @param id string Element ID
<span class='line'> 68</span>  * @param fail_throw boolean Throw exception if element is undefined.
<span class='line'> 69</span>  * @return mixed Element value.
<span class='line'> 70</span>  */</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getValueByElementId</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">  </span><span class="NAME">fail_throw</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="STRN">'undefined'</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">element</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">getValidElementById</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">isNull</span><span class="PUNC">(</span><span class="NAME">element</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">element.value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 77</span> 
<span class='line'> 78</span> </span><span class="COMM">/**
<span class='line'> 79</span>  * Set value of valid document element.
<span class='line'> 80</span>  *
<span class='line'> 81</span>  * @param id string Element ID
<span class='line'> 82</span>  * @param value mixed
<span class='line'> 83</span>  * @param fail_throw boolean Throw exception if element is undefined.
<span class='line'> 84</span>  * @return void
<span class='line'> 85</span>  */</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">setValueByElementId</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">  </span><span class="NAME">fail_throw</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="STRN">'undefined'</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">element</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">getValidElementById</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fail_throw</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">isNull</span><span class="PUNC">(</span><span class="NAME">element</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">    </span><span class="NAME">element.value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="PUNC">}</span><span class="PUNC">;</span></pre></body></html>